var fs = require('fs');
module.exports = function(app){

	app.get('/app/createPrice', function(req, res) {
		var LocationObject = AV.Object.extend("DHLocation");
		var query = new AV.Query(LocationObject);
		
		query.find({
		  success : function(results){
	  		var PriceTypeObject = AV.Object.extend("DHPriceType");
	  		var typeQuery = new AV.Query(PriceTypeObject);
	  		typeQuery.find({
		  		success : function(typeResults){
		  			res.render('create_price', { LocationObjects : results , PriceTypeObjects : typeResults});
		  		},
		  		error : function(error){
			  		res.render('error', { message: error.message });
			  		console.log('signin false: %j', error.code +" : "+ error.message);	
		  		}
		  	});
	  		
		  },
		  error: function(error) {
			res.render('error', { message: error.message });
			console.log('signin false: %j', error.code +" : "+ error.message);	
		  }
		});	    
	});

	app.post('/app/createPrice', function(req, res) {
	    var currentUser = AV.User.current();
	
		var locationObj = AV.Object.createWithoutData("DHLocation", req.param('location'));
	
		console.log(req.param('priceinfo'));
		locationObj.set("priceInfo", req.param('priceinfo'));
			
			
		locationObj.save(null, {
			success: function(locationObj) {
				res.render('success', { message: '保存成功！' });
			},
			error: function(locationObj, error) {
				res.render('error', { message: error.message });
				console.log('signin false: %j', error.code +" : "+ error.message);
			}
		});	
		
	});

}
